package com.aiss.ws.activity;

import android.os.Handler;
import android.os.Message;
import android.widget.EditText;
import android.widget.TextView;

import com.aiss.ws.R;
import com.aiss.ws.utils.Command;
import com.aiss.ws.utils.Futil;
import com.aiss.ws.utils.Url;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

/**
 * Created by chenqiang on 16/5/17.
 */
@EActivity(R.layout.activity_changepassword)
public class ChangePasswordActivity extends BaseActivity {

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(msg.what== Command.HANDLECODE3){
                try {
                    showMessage(((JSONObject)msg.obj).getString("return_data"));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                finish();
            }
        }
    };

    @ViewById(R.id.title)
    TextView title_tv;


    @Click(R.id.back)
    void setBack(){
        finish();
    }

    @AfterViews
    void init() {
        title_tv.setText("修改密码");
    }
    /**
     * 用户名
     */
    @ViewById(R.id.old_password)
    EditText old_password;
    /**
     * 密码
     */
    @ViewById(R.id.password1)
    EditText password1;
    /**
     * 确认密码
     */
    @ViewById(R.id.password2)
    EditText password2;

    /**
     * 修改成功
     */
    @Click(R.id.next_button)
    void next_button(){
        if(password1.getText().toString().equals("")||password2.getText().toString().equals("")||old_password.getText().toString().equals("")){
            showMessage("密码不能为空");
            return;
        }
        HashMap<String,String> hashMap = new HashMap<>();
        hashMap.put("type","alter");
        hashMap.put("old_password",old_password.getText().toString());
        hashMap.put("new_password1",password1.getText().toString());
        hashMap.put("new_password2",password2.getText().toString());
        Futil.xutils(Url.PASSWORD,hashMap,handler, Command.HANDLECODE3);

    }




}
